<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件访问-父访问子-children</title>
</head>
<script src="../js/vue.js"></script>
<body>

<div id="app">
    <cpn ref="aaa"></cpn>
    <button @click="btnClick">按钮</button>
</div>

</body>

<template id="cpn">
    <div>
        <h2>子组件</h2>
    </div>
</template>

<script>
    const vue = new Vue({
        'el': '#app',
        'data': {},
        'methods': {
            btnClick() {
                // $children的方式访问子组件的属性或者方法

                // console.log(this.$children);
                // this.$children[0].showMessage();
                // console.log(this.$children[0].name)

                // refs的方式访问子组件的属性或者方法
                console.log(this.$refs.aaa.name);
            }
        },
        components: {
            cpn: {
                template: '#cpn',
                methods: {
                    showMessage() {
                        console.log("show Message");
                    }
                },
                data() {
                    return {
                        name: ['1', 'qx']
                    }
                }
            }
        }
    })
</script>
</html>